package domain

import (
	"github.com/lab-online/internal/class/constant"
	"github.com/lab-online/internal/class/entity"
	"github.com/lab-online/internal/shared/code"
	"github.com/lab-online/pkg/auth"
)

func (d *Domain) GetClass(
	classEntity entity.ClassEntity,
	authEntity auth.AuthEntity,
) (entity.ClassEntity, error) {
	if class, err := d.GetClassStudent(classEntity, authEntity); err != nil {
		return nil, err
	} else if teacher, err := d.userRepository.
		GetUserByUsername(class.GetTeacher()); err != nil {
		return nil, code.ErrorPicker(err, code.DatabaseUserNotFound, constant.RESTErrUserNotFound)
	} else {
		class.UpdateEntity(entity.WithTeacherVO(teacher))
		return class, nil
	}
}
